//
//  AddDeviceS4LoadingController.m
//  O2Cat
//
//  Created by xiabin on 15/12/17.
//  Copyright © 2015年 QiDao.Purifier. All rights reserved.
//

#import "AddDeviceS4LoadingController.h"
#import "TYDotIndicatorView.h"
#import "GizWifiManager.h"

@interface AddDeviceS4LoadingController ()

@property (nonatomic,strong) UIButton* cancelBtn;
@property (nonatomic,strong) TYDotIndicatorView* loadingView;

@end

@implementation AddDeviceS4LoadingController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = QGPageBG;
    [self.view addSubview:self.cancelBtn];
    [self.view addSubview:self.loadingView];
    [self layoutSubViews];
    // Do any additional setup after loading the view.
}

- (void) viewWillAppear:(BOOL)animated {
    [self setupNavStyle];
    [GizWifiManagerIns startConfig:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void) setupNavStyle {
    UIView *statusBarView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_SIZE_WIDTH, 20)];
    statusBarView.backgroundColor=QGNavBG;
    [self.view addSubview:statusBarView];
    
    self.navigationController.navigationBar.backgroundColor = QGNavBG;
    self.navigationController.navigationBar.barTintColor = QGNavBG;
    self.navigationItem.title = @"正在连接设备";
    
    
    UIButton* backBtn = [Utils NavButtonStyleNormalBLeft:YES NormalImg:@"back" AndHightLight:@"back"];
    [backBtn addTarget:self action:@selector(popBack) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
}

-(void) popBack {
    [self.navigationController popViewControllerAnimated:YES];
}

-(void) onBtnCancel {
    //AddDeviceS3WifiController* step3 = [[AddDeviceS3WifiController alloc] init];
    [self.navigationController popToRootViewControllerAnimated:YES];
}

-(void) layoutSubViews {
    //顶部排布
    __weak __typeof(&*self)weakSelf = self;
    
    /*[self.loadingView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.view.mas_top).offset(SCREEN_SIZE_HEIGHT/4);
        make.centerX.mas_equalTo(weakSelf.view.mas_centerX).offset(0);
    }];*/
    
    [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.loadingView.mas_bottom).offset(50);
        make.centerX.mas_equalTo(weakSelf.view.mas_centerX).offset(0);
        make.width.mas_equalTo(weakSelf.view.mas_width).offset(-60);
        make.height.mas_equalTo(50);
    }];
}

-(UIButton*) cancelBtn {
    if (_cancelBtn == nil) {
        _cancelBtn = [[UIButton alloc] init];
        _cancelBtn.backgroundColor = QGNavBG;
        //[_yesBtn setBackgroundImage:[UIImage imageNamed:@"add"] forState:UIControlStateNormal];
        _cancelBtn.layer.cornerRadius = 4;
        [_cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
        [_cancelBtn setTitleColor:QGTextWhite forState:UIControlStateNormal];
        [_cancelBtn setTitleColor:QGTextGrayL1 forState:UIControlStateHighlighted];
        [_cancelBtn addTarget:self action:@selector(onBtnCancel) forControlEvents:UIControlEventTouchUpInside];
    }
    return _cancelBtn;
}

-(TYDotIndicatorView*) loadingView {
    if(_loadingView == nil) {
        _loadingView = [[TYDotIndicatorView alloc] initWithFrame:CGRectMake((SCREEN_SIZE_WIDTH-200)/2, SCREEN_SIZE_HEIGHT/4, 200, 50) dotStyle:TYDotIndicatorViewStyleCircle dotColor:QGNavBG dotSize:CGSizeMake(15, 15)];
        _loadingView.layer.cornerRadius = 5.0f;
        //_loadingView.backgroundColor = [UIColor redColor];
        [_loadingView startAnimating];
    }
    return _loadingView;
}



@end
